<template>
  <div>
   <app-flyer ref="flyer" @ShopCart="ShopCart"></app-flyer>  
  <header :class="{'rs-shadow':showChangeOrder}">
		  <div>{{sell.name}} {{orderNum ? "（桌号：" + orderNum + "）":""}}</div>
		   <!--<a class="rs-pull-right"  style="right: 100px;" v-show="!showChoose&&orderState!='改单'&&orderState!='换桌'&&orderState!='查看'" @click="reChoose">换桌</a>-->
       <a class="rs-pull-right" v-show="!showChoose||orderState=='换桌'" @click="cancelOrder">{{this.orderType}}</a>
       <div class="rs-menu" v-show="false">
        <ul>
          <li>切换商户</li>
          <li>刷新菜单</li>
          <li>刷新页面</li>
        </ul>
      </div>  
	</header>
  <transition enter-active-class="animated fadeInUp" leave-active-class="animated fadeOutDown">
  <div class="rs-alert rs-choose" v-show="showChoose" ref="choose">
		<div class="rs-choose-logo rs-border-dashed"><img src="../../assets/img/logo.png"/></div>
		<div class="rs-choose-zs f16">
			<div class="rs-border-dashed" :key="item.id" v-for="item in zs">
				<div class="rs-choose-title">{{item.name}}</div>
				<ul>
          <li :key="item1.id" :class="[{'rs-active':isZsActive(item.name,item1.name)}]" v-for="item1 in item.zs" @click="zsClick(item.name,item1.name)">{{item1.name}}</li>
				</ul>
			</div>
		</div>
		<img src="../../assets/img/img-4.png" class="rs-choose-bottom"/>
	</div>
  </transition>
	<div :class="['rs-content',{'rs-shadow':showShadow}]">
		 <div class="rs-bk-img">
        <template>
          <app-banner :listImg="listImg"></app-banner>
        </template>
		 </div>
		 <div class="rs-nav">
        <div class="rs-nav-left" ref="menuWrapper" style="overflow:hidden">
		 	  <ul>
		 	  	   <li :key="item.kindId" v-for="(item,index) in menus" @click="menuClick(index,$event)"
                    :class="index==menuCurrentIndex?'rs-active':''"
                    >
                       <a>
		 	  	   	   	   <img :src="getMenuImg(item.kindNm)" class="rs-nav-img">
		 	  	   	   	   <div class="rs-nav-title-ch f13">{{item.kindNm}}</div>
		 	  	   	   </a>
                    </li>
                    <div style="height:0.4rem"></div>
		 	  </ul>
             </div>
		 	  <div class="rs-nav-right" ref="foodsWrapper"  style="overflow:hidden">
                 <ul>  
                 <div :key="item.kindId" v-for="item in menuFoods2" class="contain">
                    <h3 class="f14" id="nav1">{{item.kindNm}}</h3>
                    <ul class="rs-clearfix">
                      <li :key="food.menuId" v-for="food in item.foods" class="food-item">
                        <a @click="detailShow(food,$event)">
                            <img  v-lazy="food.pic">
                            <div class="rs-nav-title">
							 	  	    	 	 	<img class="rs-jia" src="../../assets/img/tu_jia.png" @click.stop="foodAdd(food,$event)">
							 	  	    	 	 	<div class="rs-nav-title-r">{{food.menuName}}</div>
							 	  	    	 	 	￥{{food.price/100}}
							 	  	    	 	 </div>
			 	  	     </a>
                      </li>
                    </ul>
                </div>
                <div style="height:5rem"></div>
                 </ul>
		 	  </div>
		 </div>
	</div>
  <transition enter-active-class="animated fadeInUp" leave-active-class="animated fadeOutDown">
	<div  :class="['rs-fixed-order']" v-show="showShopCart&&selectFoods.length>0">
	    <div ref="shopCartWrapper" class="shopCartWrapper" style="overflow:hidden;max-height: 3.2rem;">
        <transition-group enter-active-class="animated fadeIn" leave-active-class="animated fadeOut" tag="ul" style="overflow:hidden;">
		  	    <li :key="food.menuId" class="foodItem" v-for="food in selectFoods">
		  	  	    <div class="f14">{{food.menuName}}</div>
 	  	  	   	    <div class="f16">￥{{food.price/100}}</div>
 	  	  	   	    <div  :class="['rs-order-jiaj',{'bk-success':food.count>0}]">
						<span  :class="['minus',{'animated fadeInRight':food.count>0}]" @click="foodMinus(food)"></span>
            <span  :class="['result f16',{'animated fadeInRight':food.count>0}]" >{{food.count}}</span>							
						<span  :class="['add']" @click="foodAdd(food)"></span>
		 	  	  	</div>
		  	  </li>
        </transition-group>
      </div>  
	</div>
  </transition>
	<footer :class="{'rs-order-none':totalCount===0,'rs-shadow':showChangeOrder}" v-show="!showOrder">
		<a class="gouwuche" @click="orderCartClick">
		   <span :class="['rs-gouwuche f24',{'animated shake':shopCart==true}]"></span>
		   <span :class="['rs-gouwuche-num',{'animated shake':shopCart==true}]" ref="gwc">{{totalCount}}</span>
		</a>
		<a  class="rs-success rs-btn rs-btn-success rs-btn-wc f16 disabled" @click="orderShow"></a>
	</footer>
  <div :class="['rs-bk-shadow',{'rs-hide':!showShadow}]" @click="shadowHide"></div>
  <transition enter-active-class="animated fadeIn" leave-active-class="animated fadeOut">
    <div :class="['rs-alert','rs-detail']" v-show="showDetail" ref="detail">
      <span class="rs-clear rs-icon rs-icon-clear" @click="detailClose"></span>
      <div class="rs-detail-img">
        <img  :src="selectedFood.pic">
      </div>
      <div class="rs-detail-text f13">
      	<div class="f22" style="margin-bottom: 0.1rem;">{{selectedFood.menuName}}</div>
      	<p>{{selectedFood.description}}</p>
          <div class="rs-add">
					 	<div class="rs-detail-nav">
		           <span class="ml5 f22">￥{{selectedFood.price/100}}</span>
		        </div>
					 	<span class="rs-icon rs-icon-add" @click="foodAdd(selectedFood)"></span>
		      </div>
      </div>
    </div>
  </transition>
  <transition enter-active-class="animated fadeIn" leave-active-class="animated fadeOut">
	<div  :class="['rs-alert rs-zhifu']" v-show="showOrder">
		<span class="rs-clear rs-icon rs-icon-clear" @click="showOrder=false"></span>
		<div class="rs-detail-zhifu">
		 	  <h5 class="f12">订单号：{{order.orderId}}</h5>
        <div class="rs-order-list"  ref="orderWrapper" style="overflow:hidden"> 
        <transition-group  enter-active-class="animated fadeIn" leave-active-class="animated fadeOut" tag="ul">
             <left-slider :key="food.menuId" :item="food" :list="selectFoods" v-for="food in selectFoods">
              <img :src="food.pic" class="rs-order-img"/>
               <div class="rs-order-del" @click="foodDelete(food)">
                删除
              </div>
		 	  	  	   <div class="rs-order-body">
		 	  	  	   	    <div class="f16">{{food.menuName}}</div>
		 	  	  	   	    <div class="f18">￥{{food.price/100}}</div>
		 	  	  	   	     <div  :class="['rs-order-jiaj',{'bk-success':food.count>0}]">
						<span  :class="['minus',{'animated fadeInRight':food.count>0}]" @click="foodMinus(food)"></span>
            <span  :class="['result f16',{'animated fadeInRight':food.count>0}]" >{{food.count}}</span>							
						<span  :class="['add']" @click="foodAdd(food)"></span>
		 	  	  	</div>
		 	  	  	   	</div>    
             </left-slider>
		 	  </transition-group>
        </div>
		      <div class="rs-zhuos f16">
		      	  <input type="text" class="f16"  v-model="orderNum" placeholder="--请输入您的桌数--" />
		      </div>
		</div>
		<div class="rs-order-footer f16">
			合计:<span class="f24">￥{{totalPrice}}</span>
			 <a  class="rs-success rs-btn rs-btn-success f16" @click="submitOrder"></a>
		</div>
	</div>
    </transition>
 <transition enter-active-class="animated fadeIn" leave-active-class="animated fadeOut">
      <div class="rs-alert rs-change-order" v-show="showChangeOrder">
					<div class="rs-choose-logo rs-border-dashed"><img src="../../assets/img/logo.png" /></div>
					<ul class="f16">
            <h2 style="color: #d1a185; padding-bottom: 50px;">{{modifyOrder?modifyOrder.orderNum:""}}</h2>
            <li><a @click="doShowPreOrder">查看</a></li>
						<li><a @click="doSetPreOrder">改单</a></li>
            <li><a @click="doChangeTable">换桌</a></li>
            <li><a @click="doCancelOrder">撤单</a></li>
						<li><a @click="doClearPreOrder">清台</a></li>
					</ul>
				</div>
    </transition>
    </div>

</template>
<script>
import {
  sGetMenus,
  sSubmitOrder,
  sGetSellList,
  sGetOrderDetail,
  sCancelOrder
} from "@/service/2dfire";
import { formatDate } from "@/utils";
import BScroll from "better-scroll";
import LeftSlider from "@/components/leftSlider/leftSlider";
import banner from "@/components/banner/banner";
import flyer from "@/components/flyer/flyer";

export default {
  data() {
    return {
      sell: {},
      goods: [],
      listHeight: [],
      foodsScrollY: 0,
      selectedFood: "",
      showDetail: false,
      showShopCart: false,
      showOrder: false,
      shopCart: false,
      showChoose: true,
      modifyOrder: false,
      order: {},
      orderNum: "",
      entityId: "",
      showChangeOrder: false,
      orderState: '',
      listImg: [
        {
          url: require("../../assets/img/banner-1.jpg")
        },
        {
          url: require("../../assets/img/banner-2.jpg")
        }
      ]
    };
  },
  created() {
    this.entityId = this.$route.params.cid;
    sGetSellList().then(res => {
      this.sell = res.data[this.entityId];
    });
    sGetMenus({ entityId: this.entityId }).then(res => {
      this.goods = res.data.model;
      if (res.data.success === false) {
        alert(res.data.message);
      }
      this.$nextTick(() => {
        this._initScroll(); // 初始化scroll
        this._calculateHeight();
      });
    });
  },
  computed: {
    orderType() {
      let tp = "取消点单";
      if (this.orderState === "换桌") {
         tp = "取消换桌";
      }
      if (this.orderState === "改单") {
         tp = "取消改单";
      }
      if (this.orderState === "查看") {
         tp = "返回";
      }
      return tp;
    },
    menuCurrentIndex() {
      for (let i = 0, l = this.listHeight.length; i < l; i++) {
        let topHeight = this.listHeight[i];
        let bottomHeight = this.listHeight[i + 1];
        if (
          !bottomHeight ||
          (this.foodsScrollY >= topHeight && this.foodsScrollY < bottomHeight)
        ) {
          return i;
        }
      }
      return 0;
    },
    menus() {
      var menus = [];
      var menuids = [];
      this.goods.map(item => {
        if (menuids.indexOf(item.kindId) === -1) {
          menuids.push(item.kindId);
          menus.push({ kindId: item.kindId, kindNm: item.kindNm });
        }
      });
      return menus;
    },
    menuFoods2() {
      var foods = [];
      var menuFoods = {};
      this.goods.map(item => {
        var kind = menuFoods[item["kindId"]];
        if (!kind) {
          kind = { foods: [] };
          menuFoods[item["kindId"]] = kind;
          kind.kindId = item["kindId"];
          kind.kindNm = item["kindNm"];
          foods.push(kind);
        }
        kind.foods.push(item);
      });
      return foods;
    },
    selectFoods() {
      let foods = [];
      this.goods.forEach(good => {
        if (good.count) {
          foods.push(good);
        }
      });
      return foods;
    },
    totalCount() {
      let count = 0;
      this.selectFoods.forEach(food => {
        count += food.count;
      });
      return count;
    },
    totalPrice() {
      var tprice = 0;
      this.selectFoods.forEach(food => {
        tprice += food.count * food.price / 100;
      });
      return tprice;
    },
    showShadow() {
      return (
        this.showOrder ||
        (this.showShopCart && this.totalCount > 0) ||
        this.showDetail ||
        this.showChangeOrder
      );
    },
    zs() {
      var zs = [];
      zs = [
        {
          name: "内厅",
          zs: [
            { name: "V1" },
            { name: "V2" },
            { name: "V3" },
            { name: "卡1" },
            { name: "卡2" },
            { name: "吧1" },
            { name: "吧2" },
            { name: "吧3" },
            { name: "吧4" },
            { name: "吧5" },
            { name: "吧6" },
            { name: "吧7" },
            { name: "吧8" },
            { name: "吧9" }
          ]
        },
        {
          name: "外厅",
          zs: [
            { name: "卡1" },
            { name: "卡2" },
            { name: "圆1" },
            { name: "圆2" },
            { name: "方1" },
            { name: "方2" },
            { name: "方3" },
            { name: "方4" },
            { name: "方5" },
            { name: "方6" }
          ]
        }
      ];
      return zs;
    }
  },
  methods: {
    _initScroll() {
      this.orderScroll = new BScroll(this.$refs.orderWrapper, { click: true });
      this.menuScroll = new BScroll(this.$refs.menuWrapper, { click: true });
      this.foodsScroll = new BScroll(this.$refs.foodsWrapper, {
        click: true,
        probeType: 3
      });
      // 监控滚动事件
      this.foodsScroll.on("scroll", pos => {
        this.foodsScrollY = Math.abs(Math.round(pos.y));
      });
    },
    _calculateHeight() {
      let foodList = this.$refs.foodsWrapper.querySelectorAll(".contain");
      let height = 0;
      this.listHeight.push(height);
      for (let i = 0, l = foodList.length; i < l; i++) {
        let item = foodList[i];
        height += item.clientHeight;
        this.listHeight.push(height);
      }
    },
    zsClick(name1, name2) {
      var orderNum = name1 + "-" + name2;
      var olist = this.getOrderList();
      var order = olist[orderNum];
      if (order && (this.orderState === "换桌" || this.orderState === "点单")) {
          alert("该桌已点，请先清台！");
          return;
      }
      // 不在修改中
      if (!this.modifyOrder) {
        if (order) {
          this.showChangeOrder = true;
          this.modifyOrder = order;
        } else {
          this.orderState = "点单";
        }
      } else {
          if (this.orderState === "换桌") {
              this.orderNum = orderNum;
              this.doSetPreOrder(this.modifyOrder);
              this.submitOrder();
          }
      }
      this.orderNum = orderNum;
      this.showChoose = false;
    },
    doSetPreOrder(order) {
      order = this.modifyOrder;
      var goods = order.goods || [];
      var ids = goods.map(good => good.menuId);
      var counts = goods.map(good => good.count);
      this.goods.map(food => {
        if (ids.indexOf(food.menuId) > -1) {
          this.$set(food, "count", counts[ids.indexOf(food.menuId)]);
          this.$set(this.goods, this.goods.indexOf(food), food);
          this.modifyOrder = order;
        }
      });
      this.showChangeOrder = false;
      this.orderState = "改单";
    },
    doShowPreOrder(order) {
      order = this.modifyOrder;
      var goods = order.goods || [];
      var ids = goods.map(good => good.menuId);
      var counts = goods.map(good => good.count);
      this.goods.map(food => {
        if (ids.indexOf(food.menuId) > -1) {
          this.$set(food, "count", counts[ids.indexOf(food.menuId)]);
          this.$set(this.goods, this.goods.indexOf(food), food);
          this.modifyOrder = order;
        }
      });
      this.showChangeOrder = false;
      this.orderState = "查看";
    },
    doChangeTable() {
      this.orderState = "换桌";
      this.showChangeOrder = false;
      this.showChoose = true;
    },
    doClearPreOrder() {
      if (confirm("确定清台重新点单?") === false) {
         return;
      }
      this.clearPreOrder(this.orderNum);
      this.showChangeOrder = false;
      this.modifyOrder = null;
      this.orderState = "";
    },
    clearCache: function() {
      if (confirm("清空所有订单记录?") === false) {
        localStorage.setItem("_orderList_", JSON.stringify({}));
        location.reload();
      }
    },
    reChoose() {
      this.orderNum = "";
      this.showChoose = true;
      this.orderState = "";
      this.modifyOrder = null;
    },
    getMenuImg(name) {
      try {
        return require("../../assets/img/" + name + ".png");
      } catch (error) {
        return require("../../assets/img/其他.png");
      }
    },
    detailShow(food, event) {
      if (!event._constructed) {
        return;
      }
      this.selectedFood = food;
      this.showDetail = true;
    },
    detailClose() {
      this.showDetail = false;
    },
    orderCartClick: function() {
      if (this.selectFoods.length > 0) {
        this.showShopCart = !this.showShopCart;
      }
      if (this.showShopCart) {
        this.$nextTick(() => {
          if (!this.shopCartScroll) {
            this.shopCartScroll = new BScroll(this.$refs.shopCartWrapper, {
              click: true,
              probeType: 3
            });
          } else {
            this.shopCartScroll.refresh();
          }
        });
      }
    },
    foodAdd: function(food, event) {
      if (event && !event._constructed) {
        return;
      }
      food.count = food.count || 0;
      this.$refs.flyer.setTarget(this.$refs.gwc.getBoundingClientRect());
      this.$set(food, "count", ++food.count);
      this.$set(this.goods, this.goods.indexOf(food), food);
      this.showDetail = false;
      if (!event) {
        return false;
      }
      this.$refs.flyer.add(
        event.target.getBoundingClientRect().x,
        event.target.getBoundingClientRect().y,
        event.target.outerHTML
      );
    },
    ShopCart: function() {
      this.shopCart = true;
      setTimeout(() => {
        this.shopCart = false;
      }, 500);
    },
    foodMinus: function(food) {
      food.count = food.count || 0;
      if (food.count === 1) {
        if (confirm("确定删除商品？") === false) {
          return;
        }
      }
      if (food.count > 0) {
        this.$set(food, "count", --food.count);
        this.$set(this.goods, this.goods.indexOf(food), food);
      }
      if (this.totalCount === 0) {
        this.showShopCart = 0;
      }
    },
    foodClear: function() {
      if (confirm("确定清空已点商品？") === false) {
        return;
      }
      this.selectFoods.map(food => {
        this.$set(food, "count", 0);
        this.$set(this.goods, this.goods.indexOf(food), food);
      });
      this.showShopCart = false;
    },
    foodDelete: function(food) {
      if (confirm("确定删除商品？") === false) {
        return;
      }
      this.$set(food, "count", 0);
      this.$set(this.goods, this.goods.indexOf(food), food);
    },
    menuClick(index, $event) {
      this.foodsScroll.scrollTo(0, -this.listHeight[index], 300);
    },
    shadowHide: function() {
      if (this.showShopCart) {
        this.showShopCart = false;
      }
      if (this.showDetail) {
        this.showDetail = false;
      }
      if (this.showOrder) {
        this.showOrder = false;
      }
      if (this.showChangeOrder) {
        this.showChangeOrder = false;
        this.showChoose = true;
        this.orderState = "";
        this.orderNum = "";
        this.modifyOrder = null;
      }
    },
    orderShow: function() {
      if (this.selectFoods.length === 0) {
        return;
      }
      this.showShopCart = false;
      this.showDetail = false;
      this.showOrder = true;
      this.selectFoods.map(food => {
        this.$set(food, "className", "");
      });
      this.order = {};
      this.order["orderId"] = new Date().getTime();
      this.order["name"] = "";
      this.$nextTick(() => {
        if (!this.orderScroll) {
          this.orderScroll = new BScroll(this.$refs.orderWrapper, {
            click: true,
            probeType: 3
          });
        } else {
          this.orderScroll.refresh();
        }
      });
    },
    submitOrder() {
      if (this.selectFoods.length === 0) {
        alert("未选择任何商品！");
        return;
      }
      if (this.sell.isCanOder !== true) {
        alert("防止乱下单，暂时不允许下单！");
        return;
      }
      var para = {};
      para["entityId"] = this.entityId;
      var thirdpartWMOrderBo = {};
      para["thirdpartWMOrderBo"] = thirdpartWMOrderBo;
      thirdpartWMOrderBo["orderId"] = new Date().getTime();
      thirdpartWMOrderBo["orderFrom"] = "118";
      thirdpartWMOrderBo["address"] = "118";
      thirdpartWMOrderBo["viewId"] = thirdpartWMOrderBo["orderId"];
      thirdpartWMOrderBo["phoneNo"] = this.orderNum + "号桌";
      thirdpartWMOrderBo["name"] = "";
      thirdpartWMOrderBo["outFee"] = "0";
      thirdpartWMOrderBo["realPrice"] = this.totalPrice / 100;
      thirdpartWMOrderBo["totalPrice"] = this.totalPrice / 100;
      thirdpartWMOrderBo["hasInvoiced"] = true;
      thirdpartWMOrderBo["reserveDate"] = 0;
      thirdpartWMOrderBo["book"] = false;
      thirdpartWMOrderBo["isThirdShipping"] = 2;
      thirdpartWMOrderBo["daySeq"] = this.orderNum + "号桌";
      thirdpartWMOrderBo["peopleCount"] = 1;
      thirdpartWMOrderBo["income"] = 0;
      thirdpartWMOrderBo["payType"] = 1;
      var cartBoList = [];
      thirdpartWMOrderBo["cartBoList"] = cartBoList;
      this.selectFoods.map(food => {
        cartBoList.push({
          menuId: food.menuId,
          name: food.menuName,
          price: food.price / 100,
          num: food.count,
          fee: food.price * food.count / 100,
          boxPrice: 0,
          boxNum: 0,
          unit: food.unit
        });
      });
      if (this.modifyOrder) {
        thirdpartWMOrderBo["memo"] = this.getOrderDiff(
          this.modifyOrder.goods,
          this.selectFoods
        );
        if (this.modifyOrder["orderNum"] !== this.orderNum) {
          thirdpartWMOrderBo["memo"] +=
            "\n换桌\n[" +
            this.modifyOrder["orderNum"] +
            "]换[" +
            this.orderNum +
            "]";
        }
        // thirdpartWMOrderBo["extras"] = thirdpartWMOrderBo["memo"];
        let memo = thirdpartWMOrderBo["memo"]; 
        thirdpartWMOrderBo["phoneNo"] = thirdpartWMOrderBo["memo"]; 
        if (memo.length > 100) {
          memo = memo.substr(0, 95) + "。。。";
        }
        if (memo.length > 50 && memo.length < 100) {
          thirdpartWMOrderBo["name"] = memo.substr(0, memo.substr(0, 49).lastIndexOf('\n'));
          thirdpartWMOrderBo["phoneNo"] = memo.substr(memo.substr(0, 49).lastIndexOf('\n'));  
        } 

        // thirdpartWMOrderBo["memo"];
      }
      sSubmitOrder(para).then(res => {
        if (res.data.success) {
          this.showOrder = false;
          // memo
          if (this.modifyOrder) {
            this.$toast(this.orderState + "成功!");
            sCancelOrder({
              outOrderId: this.modifyOrder.orderId,
              orderFrom: "118",
              reason: this.orderState
            });
          } else {
            this.$toast("下单成功!");
          }
          this.setOrderList(this.orderNum, {
            orderId: thirdpartWMOrderBo["orderId"],
            goods: this.selectFoods
          });
          this.selectFoods.map(food => {
            this.$set(food, "count", 0);
            this.$set(this.goods, this.goods.indexOf(food), food);
          });
          this.showChoose = true;
          this.orderNum = "";
          this.modifyOrder = null;
          this.orderState = "";
        }
      });
    },
    doCancelOrder() {
      if (confirm("确定撤销该订单？") === false) {
          return;
      }
      if (this.modifyOrder) {
            sCancelOrder({
              outOrderId: this.modifyOrder.orderId,
              orderFrom: "118",
              reason: this.orderState
            }).then(res => {
                 if (res.data.success) {
                    this.$toast("撤单成功!");
                    this.clearPreOrder(this.orderNum);
                    this.showChoose = true;
                    this.showChangeOrder = false;
                    this.orderNum = "";
                    this.modifyOrder = null;
                 }
            });
      } else {
         this.$toast("状态不合法！");
      }
    },
    getOrderDiff(preGoods, goods) {
      let aadd = [];
      let amin = [];
      goods.map(food => {
        let pfoods = preGoods.find(function(value, index, arr) {
          return value["menuId"] === food["menuId"];
        });
        // 新增
        if (!pfoods) {
          aadd.push("" + food["menuName"] + " " + food.count + food.unit);
        } else {
          // 修改
          let cc = food.count - pfoods.count;
          if (cc < 0) {
            amin.push("" + food["menuName"] + " " + cc + food.unit);
          }
          if (cc > 0) {
            aadd.push("" + food["menuName"] + " " + cc + food.unit);
          }
        }
      });
      preGoods.map(pfood => {
        let food = goods.find(function(value, index, arr) {
          return value["menuId"] === pfood["menuId"];
        });
        if (!food) {
          let cc = pfood.count * -1;
          amin.push("" + pfood["menuName"] + " " + cc + pfood.unit);
        }
      });
      console.log(aadd);
      let ret = "";
      if (aadd.length > 0) {
        ret += "\n加：\n" + aadd.join("\n");
      }
      if (amin.length > 0) {
        ret += "\n减：\n" + amin.join("\n");
      }
      if (ret !== "") {
        ret = "改单" + ret;
      }
      return ret;
    },
    setOrderList(orderNum, order) {
      var list = localStorage.getItem("_orderList_") || "{}";
      var olist = JSON.parse(list);
      if (this.modifyOrder && orderNum !== this.modifyOrder["orderNum"]) {
        olist[this.modifyOrder["orderNum"]] = "";
      }
      olist[orderNum] = order;
      order["orderNum"] = orderNum;
      localStorage.setItem("_orderList_", JSON.stringify(olist));
    },
    clearPreOrder(orderNum) {
      var list = localStorage.getItem("_orderList_") || "{}";
      var olist = JSON.parse(list);
      olist[this.modifyOrder["orderNum"]] = null;
      delete olist[this.modifyOrder["orderNum"]];
      localStorage.setItem("_orderList_", JSON.stringify(olist));
    },
    getOrderList() {
      var list = localStorage.getItem("_orderList_") || "{}";
      var olist = JSON.parse(list);
      return olist;
    },
    isZsActive(name1, name2) {
      let orderNum = name1 + "-" + name2;
      let olist = this.getOrderList();
      return !!olist[orderNum];
    },
    changeOrder(order) {
      sGetOrderDetail({
        entityId: this.entityId,
        currDate: formatDate(new Date(), "yyyyMMdd")
      });
    },
    cancelChangeOrder() {},
    cancelOrder() {
      if (this.orderState === "换桌") {
        this.orderState = ""; 
        this.showChoose = false;
        this.showChangeOrder = true;
        return;
      }
      this.selectFoods.map(food => {
        this.$set(food, "count", 0);
        this.$set(this.goods, this.goods.indexOf(food), food);
      });
      this.showChoose = true;
      this.orderNum = "";
      this.modifyOrder = null;
      this.orderState = "";
    },
    getCartPostion() {
      return { x: 100, y: 100 };
    }
  },
  components: {
    LeftSlider,
    "app-banner": banner,
    "app-flyer": flyer
  }
};
</script>
<style lang="stylus">
@import '../../assets/css/iconfont.css';
@import '../../assets/css/css.css';
@import '../../assets/css/animate.min.css';

.rs-menu {
  display: inline-block;
  position: absolute;
  right: 0;
  background-color: #f7f6f6;
  color: black;
}

.rs-fixed-order {
  .shopCartWrapper {
    ul {
      max-height: none;
    }
  }
}
</style>
